package gamemodel.clock;

public class Counter {
	
	private int currCount; //represents current count 
	private transient int initCount ; //represents the initial count, to reset if needed (ie. rollover)
	private transient Counter nextCounter;  //represents next counter impacted due to roll over 
	
	//static constant representing a default count value
	public static int DEFAULT_COUNT = 5; 
	
	//static constant representing a default timer value
	public static int DEFAULT_TIME = 60;
	
	
	public Counter(){
		this(DEFAULT_COUNT); 
	}
	
	public Counter(int count){
		this.currCount = count; 
		this.initCount = count; 
		this.nextCounter = null; 
	}
	
	/**
	 * Determines current count 
	 * @return current count value
	 */
	public int getCount(){
		return this.currCount; 
	}
	
	/**
	 * Sets a reference to the next Count object affected by a roll over
	 * @param c Counter object being affected 
	 */
	public void setNextCounter(Counter c){
		this.nextCounter = c ; 
	}
	
	/**
	 * Decrements the current count value. Also updates the next Count object's 
	 * count value when roll over occurs, if any. 
	 */
	public void decrement(){
		//if counter rolloved over to inital Count or if this is the first tick, 
		//counter should decrement the next Counter's count (ie. 2:00 -> 1:59, 
		//specifically look at hour hand)
		/*if (this.nextCounter != null && this.currCount == this.initCount){
			this.nextCounter.decrement();
		}*/
		
		if (this.currCount > 0 ){
			this.currCount = this.currCount - 1;
		}
		
		//reset current Counter count if the next Counter isn't zero yet
		if (this.currCount == 0){
			if (this.nextCounter != null){
				if (this.nextCounter.getCount() > 0){
					//this.currCount = this.initCount;
					this.currCount = DEFAULT_TIME;
				}
				this.nextCounter.decrement();
			}	
		}
		 
		
		
	}
	
}
